package com.hxkj.controller;

import com.hxkj.client.service.TokenServiceClient;
import com.hxkj.domain.enums.UserExceptionEnum;
import com.hxkj.domain.po.LoginToken;
import com.hxkj.service.TokenService;
import com.platform.common.domain.exception.CustomException;
import com.platform.common.domain.result.ResultDataStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * created by kezhijie on 2018/8/31 14:47.
 * email to kezhijie@hxoss.com
 */
@RestController
@RequestMapping("token")
public class TokenController {

    @Autowired
    private TokenService tokenService;
    //private TokenServiceClient tokenServiceClient;

    @GetMapping("refresh")
    public LoginToken refresh(@RequestParam("token") String token) throws Exception {
        ResultDataStruct<LoginToken> resultDataStruct = tokenService.refresh(token);

        if (resultDataStruct.getCode() != 200)
            throw new CustomException(UserExceptionEnum.getEnumByCode(resultDataStruct.getCode()));

        return resultDataStruct.getData();
    }
}
